package com.example.zbh.dsliao.ui.activty;

import android.content.res.AssetManager;
import android.graphics.Typeface;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.zbh.dsliao.R;
import com.example.zbh.dsliao.constant.Constant;
import com.example.zbh.dsliao.utils.PreferenceHelper;

import static android.R.color.black;

/**
 * Created by zbh on 15/12/1.
 */
public class TypeFaceActivity extends BaseActivity implements View.OnClickListener {
    private TextView typeFace_tv, common_tv, little_tv, letter_tv, color_tv,
            black_tv, white_tv, green_tv, red_tv, size_tv, large_tv, middle_tv, small_tv;
    private String textType;
    private String textColor;
    private String textSize;
    private AssetManager assetManager;
    private Typeface typeface;
    private LinearLayout back;

    @Override
    protected int getLayOut() {
        return R.layout.activity_type_face;
    }

    @Override
    protected void initView() {
        typeFace_tv = findeView(R.id.typeFace_tv);
        common_tv = findeView(R.id.common_tv);
        little_tv = findeView(R.id.little_tv);
        letter_tv =findeView(R.id.letter_tv);
        color_tv = findeView(R.id.color_tv);
        black_tv = findeView(R.id.black_tv);
        white_tv = findeView(R.id.white_tv);
        green_tv = findeView(R.id.green_tv);
        red_tv = findeView(R.id.red_tv);
        size_tv = findeView(R.id.size_tv);
        large_tv = findeView(R.id.large_tv);
        middle_tv = findeView(R.id.middle_tv);
        small_tv = findeView(R.id.small_tv);
        back = findeView(R.id.back);

    }

    @Override
    protected void initData() {
        assetManager = getAssets();
        textType = PreferenceHelper.getInstance().getCurrentTextType();
        textColor = PreferenceHelper.getInstance().getCurrentuserTextColor();
        textSize = PreferenceHelper.getInstance().getCurrentTextSize();
        setTextType();
        setTextColor();
        setTextSize();
        common_tv.setOnClickListener(this);
        little_tv.setOnClickListener(this);
        letter_tv.setOnClickListener(this);
        black_tv.setOnClickListener(this);
        white_tv.setOnClickListener(this);
        green_tv.setOnClickListener(this);
        red_tv.setOnClickListener(this);
        large_tv.setOnClickListener(this);
        middle_tv.setOnClickListener(this);
        small_tv.setOnClickListener(this);
        back.setOnClickListener(this);

    }




    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.common_tv:
                PreferenceHelper.getInstance().setCurrentTextType(Constant.TYPE_03);
                typeface = Typeface.DEFAULT;
                textType(typeface);
                break;
            case R.id.little_tv:
                PreferenceHelper.getInstance().setCurrentTextType(Constant.TYPE_01);
                typeface = Typeface.createFromAsset(assetManager,"xindixiaowanzi.ttf");
                textType(typeface);
                break;
            case R.id.letter_tv:
                PreferenceHelper.getInstance().setCurrentTextType(Constant.TYPE_02);
                typeface = Typeface.createFromAsset(assetManager,"xindiwenguimingti.ttf");
                textType(typeface);
                break;
            case R.id.black_tv:
                Log.i("nannannan", "black");
                PreferenceHelper.getInstance().setCurrentTextColor(Constant.COLOR_01);
                int colorb = Constant.COLOR_BLACK;
                textColor(colorb);
                break;
            case R.id.white_tv:
                Log.i("nannannan", "white_tv");
                PreferenceHelper.getInstance().setCurrentTextColor(Constant.COLOR_02);
                int colorw = Constant.COLOR_WHITE;
                textColor(colorw);
                break;
            case R.id.green_tv:
                Log.i("nannannan", "green_tv");
                PreferenceHelper.getInstance().setCurrentTextColor(Constant.COLOR_03);
                int colorg = Constant.COLOR_GREEN;
                textColor(colorg);

                break;
            case R.id.red_tv:
                Log.i("nannannan", "red_tv");
                PreferenceHelper.getInstance().setCurrentTextColor(Constant.COLOR_04);
                int colorr = Constant.COLOR_RED;
                textColor(colorr);

                break;
            case R.id.large_tv:
                PreferenceHelper.getInstance().setCurrentTextSize(Constant.SIZE_01);
                float l = Constant.SIZE_LARGE;
                textSize(l);
                break;
            case R.id.middle_tv:
                PreferenceHelper.getInstance().setCurrentTextSize(Constant.SIZE_02);
                float m = Constant.SIZE_MIDDLE;
                textSize(m);
                break;
            case R.id.small_tv:
                PreferenceHelper.getInstance().setCurrentTextSize(Constant.SIZE_03);
                float s = Constant.SIZE_SMALL;
                textSize(s);
                break;
            case R.id.back:
                finish();
                break;

        }
    }
    private void setTextType() {
        if (textType != null){
            switch (textType){
                case Constant.TYPE_01:
                    typeface = Typeface.createFromAsset(assetManager,"xindixiaowanzi.ttf");
                    textType(typeface);
                    break;
                case Constant.TYPE_02:
                    typeface = Typeface.createFromAsset(assetManager,"xindiwenguimingti.ttf");
                    textType(typeface);
                    break;
                case Constant.TYPE_03:
                    typeface = Typeface.DEFAULT;
                    textType(typeface);
                    break;
            }
        }

    }
    private void setTextColor() {
        if (textColor != null){
            switch (textColor){
                case Constant.COLOR_01:
                    int colorb = Constant.COLOR_BLACK;
                    textColor(colorb);
                    break;
                case Constant.COLOR_02:
                    int colorw = Constant.COLOR_WHITE;
                    textColor(colorw);
                    break;
                case Constant.COLOR_03:
                    int colorr = Constant.COLOR_GREEN;
                    textColor(colorr);
                    break;
                case Constant.COLOR_04:
                    int colorg = Constant.COLOR_RED;
                    textColor(colorg);
                    break;
            }
        }


    }
    private void setTextSize() {
        if (textSize != null){
            switch (textSize){
                case Constant.SIZE_01:
                    float l = Constant.SIZE_LARGE;
                    textSize(l);
                    break;
                case Constant.SIZE_02:
                    float m = Constant.SIZE_MIDDLE;
                    textSize(m);
                    break;
                case Constant.SIZE_03:
                    float s = Constant.SIZE_SMALL;
                    textSize(s);
                    break;
            }
        }


    }
    private void textType(Typeface typeface){
        typeFace_tv.setTypeface(typeface);
        common_tv.setTypeface(typeface);
        little_tv.setTypeface(typeface);
        letter_tv.setTypeface(typeface);
        color_tv.setTypeface(typeface);
        black_tv.setTypeface(typeface);
        white_tv.setTypeface(typeface);
        green_tv.setTypeface(typeface);
        red_tv.setTypeface(typeface);
        size_tv.setTypeface(typeface);
        large_tv.setTypeface(typeface);
        middle_tv.setTypeface(typeface);
        small_tv.setTypeface(typeface);
    }
    private void textColor(int color){
        typeFace_tv.setTextColor(color);
        common_tv.setTextColor(color);
        little_tv.setTextColor(color);
        letter_tv.setTextColor(color);
        color_tv.setTextColor(color);
        black_tv.setTextColor(color);
        white_tv.setTextColor(color);
        green_tv.setTextColor(color);
        red_tv.setTextColor(color);
        size_tv.setTextColor(color);
        large_tv.setTextColor(color);
        middle_tv.setTextColor(color);
        small_tv.setTextColor(color);

    }
    private void textSize(float size){
        typeFace_tv.setTextSize(size);
        common_tv.setTextSize(size);
        little_tv.setTextSize(size);
        letter_tv.setTextSize(size);
        color_tv.setTextSize(size);
        black_tv.setTextSize(size);
        white_tv.setTextSize(size);
        green_tv.setTextSize(size);
        red_tv.setTextSize(size);
        size_tv.setTextSize(size);
        large_tv.setTextSize(size);
        middle_tv.setTextSize(size);
        small_tv.setTextSize(size);
    }



}
